<!--
 * @Description:救援单新增/编辑
 * @Autor: 刘诗文
 * @Date: 2020-11-16 16:56:25
 * @LastEditors: 刘诗文
 * @LastEditTime: 2021-01-27 15:39:24
-->
<template>
  <div>
    <div class="wrapper">
      <!-- <Anchor :labelList="labels" :labelWidth="85"> -->
      <div>
        <FormPanel ref="formPanel" :list="formList" :cols="4" :labelWidth="105" :formType="type" :isSubmitBtn="false" />
      </div>
     <BaseDialog :visible.sync="vinSelect" :title="'VIN选择'" width="850px" destroyOnClose :containerStyle="{height: 'calc(100% - 60px)', overflow: 'auto', paddingBottom: '60px'}">
       <SelectVin @close="vinClose" @save="selectVinSave" :rowDate="rowDate"></SelectVin>
     </BaseDialog>
      <BaseDialog width="850px" :visible.sync="partCodeSelect" title="故障件选择" destroyOnClose :containerStyle="{ height: 'calc(100% - 70px)', overflow: 'auto', paddingBottom: '70px' }">
        <partCodeFrom @close="closePartCode" @save="partCodeSelectSave" :rowDate="rowDatePartCode" />
      </BaseDialog>
      <!-- </Anchor> -->
    </div>
    <div
      :style="{
        position: 'absolute',
        left: 0,
        bottom: 0,
        right: 0,
        zIndex: 9,
        borderTop: '1px solid #e9e9e9',
        padding: '10px 20px',
        background: '#fff',
        textAlign: 'right'
      }"
    >
      <AjaxButton type="primary" :click="saveHandler" v-if="saveVisable === true">保存</AjaxButton>
      <AjaxButton type="primary" :click="reported" v-if="saveVisable === true">上报</AjaxButton>
      <el-button @click="closeHandler">关闭</el-button>
    </div>
  </div>
</template>

<script>
import { dictionary } from '@/utils/dictMixin';
import { isFormEmpty, notifyAction } from '@/utils';
import moment from 'moment';
import selectCustomer from './selectCustomer';
import { getRoLogList} from '@/api/claim/dealer/ClaimApplication/index';
import { reportedOut,getOutNo, saveOut } from '@/api/customerRepair/rescueManagement/rescueOrder';
import {  getCheModelSelect } from '@/api/repair/repairReception/customer/brand.js';
import { getProvince, getCitys, getDistrict } from '@/api/customerRepair/customerInfo/ownerVehicleManagement';
import SelectVin from './SelectVin.vue';
import { phone,partCodeP,numberCheck } from '@/utils/validate';
import partCodeFrom from './partCodeFrom'

export default {
  name: 'addRescuePanel',
  components: {
    selectCustomer,
    SelectVin,
    partCodeFrom
  },
  mixins: [dictionary],
  props: {
    type: {
      type: String
    },
    formData: {
      type: Object,
      default: () => ({})
    },
      value:{
      type: Object,
      default: null
    }
  },
  data() {
    this.selectRow = null;
    this.BaseTable = null;
    this.resData = {};
    return {
      formList: this.createFromList(),
      tableParamData: {},
      actions: { visible: false, title: '' }, // 弹出面板的相关信息
      tableList: [],
      addVisable: true,
      tableVisable: false,
      rescueButton: false,
      saveVisable: true,
      delVisable: true,
      vinSelect: false,
      rowDate: {},
      rowDatePartCode: {},
      out: {},
      partCodeSelect: false
    };
  },
  mounted() {
    this.BaseTable = this.$refs.table;
    this.initHandle();
    // 获取省
    this.getProvine();
  },
  methods: {
    createFromList() {
      return [
        {
          type: 'BREAK_SPACE',
          label: '车辆信息'
        },
        {
          type: 'INPUT',
          label: 'VIN',
          fieldName: 'vin',
          initialValue: '',
          readonly: true,
          placeholder: '',
          rules: [{ required: true, message: '请输入VIN', trigger: 'blur' }],
          unitRender: () => {
            return <el-button  icon="el-icon-search" onClick={this.vinOpen}></el-button>;
          }
        },
        {
          type: 'INPUT',
          label: '电机号',
          fieldName: 'engineCode',
          initialValue: '',
          disabled: true
        },
        {
          type: 'INPUT',
          label: '车牌号',
          fieldName: 'vhlPlate',
          initialValue: '',
          disabled: true
        },
        {
          type: 'INPUT',
          label: '车系',
          fieldName: 'vehicleSeries',
          itemList: [],
          disabled: true
        },
        {
          type: 'INPUT',
          label: '车型',
          fieldName: 'vehicleType',
          itemList: [],
          disabled: true
        },
        {
          type: 'INPUT_NUMBER',
          label: '行驶里程',
          fieldName: 'nowMile',
          disabled: true
        },
        {
          type: 'DATE',
          label: '保修起始日期',
          placeholder: '请选择',
          fieldName: 'warrantyStartDate',
          valueFormat: 'yyyy-MM-dd', //返回数据格式
          initialValue: '',
          disabled: true,
        },
        {
          type: 'INPUT',
          label: '车主姓名',
          fieldName: 'ownerName',
          initialValue: '',
          disabled: true
        },
        {
          type: 'INPUT',
          label: '车主手机号',
          fieldName: 'ownerTel',
          initialValue: '',
          rules: [{ trigger: 'blur', validator: phone }],
          disabled: true
        },
        {
          type: 'BREAK_SPACE',
          label: '救援信息'
        },
        {
          type: 'INPUT',
          label: '救援单号',
          fieldName: 'outNo',
          initialValue: '',
          disabled: true,
        },
        {
          type: 'INPUT',
          label: '报修人',
          fieldName: 'cmsClaimName',
          initialValue: '',
          rules: [{ required: true, message: '请输入报修人', trigger: 'blur' }],
          
        },
        {
          type: 'INPUT',
          label: '报修人电话',
          fieldName: 'cmsClaimTel',
          initialValue: '',
          rules: [{ required: true, message: '请输入报修人电话', trigger: 'blur', validator: phone }]
        },
        {
          type: 'DATE',
          label: '申请日期',
          fieldName: 'applyDate',
          dateType: 'datetime',
          initialValue: moment().format('YYYY-MM-DD HH:mm:ss'),
          disabled: true
        },
        {
          type: 'INPUT',
          label: '故障件代码',
          fieldName: 'partCode',
          initialValue: '',
          placeholder: '',
          readonly: true,
          rules: [{ required: true, validator: partCodeP, trigger: 'blur' }
                 ,{ required: true, message: '请输入故障件代码', trigger: 'blur' }],
          unitRender: () => {
            return (
              <div>
                <el-button icon="el-icon-search" onClick={() => this.addPartCode()}></el-button>
              </div>
            );
          },
        },
        {
          type: 'INPUT',
          label: '故障件名称',
          fieldName: 'partName',
          initialValue: '',
          disabled: true
        },
        {
          type: 'INPUT',
          label: '处理结果',
          fieldName: 'dealResult',
          selfCols: 4,
          initialValue: ''
        },
        {
          type: 'INPUT',
          label: '外出原因',
          fieldName: 'outReason',
          selfCols: 4,
          initialValue: '',
          rules: [{ required: true, message: '请输入外出原因', trigger: 'blur' }],
        },
        {
          type: 'INPUT',
          label: '用户意见',
          fieldName: 'opinion',
          selfCols: 4,
          initialValue: ''
        },
        {
          type: 'INPUT',
          label: '外出人员',
          fieldName: 'outPerson',
          selfCols: 2,
          initialValue: '',
          rules: [{ required: true, message: '请输入外出人员', trigger: 'blur' }],
        },
        {
          type: 'SELECT',
          label: '外出方式',
          fieldName: 'outType',
          itemList: this.createDictList(5538),
          rules: [{ required: true, message: '请输入外出方式', trigger: 'change' }],
          change: val => {
            this.outType(val);
          }
        },
        {
          type: 'SELECT',
          label: '是否拖车',
          fieldName: 'isTrailer',
          itemList: this.createDictList(1004),
          rules: [{ required: true, message: '请输入是否拖车', trigger: 'change' }],
          change: val => {
            this.isTrailer(val);
          }
        },
        {
          type: 'SELECT',
          label: '出发省份',
          fieldName: 'fromP',
          itemList: [],
          rules: [{ required: true, message: '请输入出发省份', trigger: 'change' }],
          change: val => {
            this.provinceChange(val);
          }
        },
        {
          type: 'SELECT',
          label: '出发城市',
          fieldName: 'fromC',
          itemList: [],
          rules: [{ required: true, message: '请输入出发城市', trigger: 'change' }],
          change: val => {
            this.cityChange(val);
          }
        },
        {
          type: 'SELECT',
          label: '出发区县',
          fieldName: 'fromA',
          itemList: [],
          rules: [{ required: true, message: '请输入出发区县', trigger: 'change' }],
        },
        {
          type: 'INPUT',
          label: '出发地址',
          fieldName: 'fromAddress',
          selfCols: 4,
          initialValue: '',
          rules: [{ required: true, message: '请输入出发地址', trigger: 'blur' }],
        },
        {
          type: 'SELECT',
          label: '故障地省份',
          fieldName: 'toP',
          itemList: [],
          rules: [{ required: true, message: '请输入故障地省份', trigger: 'change' }],
          change: val => {
            this.toProvinceChange(val);
          }
        },
        {
          type: 'SELECT',
          label: '故障地城市',
          fieldName: 'toC',
          itemList: [],
          rules: [{ required: true, message: '请输入故障地城市', trigger: 'change' }],
          change: val => {
            this.toCityChange(val);
          }
        },
        {
          type: 'SELECT',
          label: '故障地区县',
          fieldName: 'toA',
          itemList: [],
          rules: [{ required: true, message: '请输入故障地区县', trigger: 'change' }],
        },
        {
          type: 'SELECT',
          label: '是否偏远地区',
          fieldName: 'isFar',
          itemList: this.createDictList(1004),
          rules: [{ required: true, message: '请输入是否偏远地区', trigger: 'change' }],
        },
        {
          type: 'INPUT',
          label: '故障发生地址',
          fieldName: 'toAddress',
          selfCols: 4,
          initialValue: '',
          rules: [{ required: true, message: '请输入故障发生地址', trigger: 'blur' }],
        },
        {
          type: 'INPUT',
          label: '外出路线',
          fieldName: 'outLine',
          selfCols: 4,
          initialValue: '',
          rules: [{ required: true, message: '请输入外出路线', trigger: 'blur' }],
        },
        {
          type: 'INPUT',
          label: '救援双边里程',
          fieldName: 'outMile',
          rules: [{ required: true, validator: numberCheck, trigger: 'blur' },
                  {required: true, message: '请输入救援双边里程', trigger: 'blur' }]
          
        },
        {
          type: 'INPUT',
          label: '人数',
          fieldName: 'outPersons',
          rules: [{ required: true, validator: numberCheck, trigger: 'blur' },
                  { required: true, message: '请输入人数', trigger: 'blur' }],
        },
        {
          type: 'RANGE_DATE',
          label: '救援时间',
          fieldName: 'bDate|eDate',
          selfCols: 2,
          placeholder: '请输入',
          dateType: 'daterange',
          initialValue: '',
          rules: [{ required: true, message: '请输入救援时间', trigger: 'blur' }],
        },
        {
          type: 'BREAK_SPACE',
          label: '费用信息',
        },
        {
          type: 'INPUT',
          label: '燃油补贴',
          fieldName: 'fuelSubsidy',
          rules: [{ required: true, validator: numberCheck, trigger: 'blur' },
                  { required: true, message: '请输入燃油补贴', trigger: 'blur' }],
          initialValue: '',
          change: val => {
            this.allAmountChange();
          },
        },
        {
          type: 'INPUT',
          label: '人员补贴',
          fieldName: 'prSubsidy',
          rules: [{ required: true, validator: numberCheck, trigger: 'blur' },
                  { required: true, message: '请输入人员补贴', trigger: 'blur' }],
          initialValue: '',
          change: val => {
            this.allAmountChange();
          },
        },
        {
          type: 'INPUT',
          label: '餐补',
          fieldName: 'foodSubsidy',
          rules: [{ required: true, validator: numberCheck, trigger: 'blur' },
                  { required: true, message: '请输入餐补', trigger: 'blur' }],
          initialValue: '',
          change: val => {
            this.allAmountChange();
          },
        },
        {
          type: 'INPUT',
          label: '住宿补贴',
          fieldName: 'staySubsidy',
          rules: [{ required: true, validator: numberCheck, trigger: 'blur' },
                  { required: true, message: '请输入住宿补贴', trigger: 'blur' }],
          initialValue: '',
          change: val => {
            this.allAmountChange();
          },
        },
        {
          type: 'INPUT',
          label: '车船票',
          fieldName: 'crossAmount',
          rules: [{ required: true, validator: numberCheck, trigger: 'blur' },
                  { required: true, message: '请输入车船票', trigger: 'blur' }],
          initialValue: '',
          change: val => {
            this.allAmountChange();
          },
        },
        {
          type: 'INPUT',
          label: '拖车费',
          fieldName: 'trailerAmount',
          rules: [{ required: true, validator: numberCheck, trigger: 'blur' },
                  { required: true, message: '请输入拖车费', trigger: 'blur' }],
          initialValue: '',
          change: val => {
            this.allAmountChange();
          },
        },
        {
          type: 'INPUT',
          label: '其他费用',
          fieldName: 'otherAmount',
          rules: [{ required: true, validator: numberCheck, trigger: 'blur' },
                  { required: true, message: '请输入其他费用', trigger: 'blur' }],
          initialValue: '',
          change: val => {
            this.allAmountChange();
          },
        },
        {
          type: 'SELECT',
          label: '激励类型',
          fieldName: 'rewardType',
          initialValue: '',
          rules: [{ required: true, message: '请输入激励类型', trigger: 'change' }],
          itemList: this.createDictList(5537)
        },
        {
          type: 'INPUT',
          label: '奖励金额',
          fieldName: 'rewardFee',
          rules: [{ required: true, validator: numberCheck, trigger: 'blur' },
                  { required: true, message: '请输入奖励金额', trigger: 'blur' }],
          initialValue: '',
          change: val => {
            this.allAmountChange();
          },
        },
        {
          type: 'INPUT',
          label: '合计费用',
          fieldName: 'allAmount',
          disabled: true,
          rules: [{ required: true, message: '请输入合计费用', trigger: 'blur' }],
          initialValue: '',
        },
        {
          type: 'INPUT',
          label: '备注',
          fieldName: 'remarks',
          selfCols: 4,
          initialValue: '',
        },
        {
          type: 'UPLOAD_FILE',
          label: '附件上传',
          fieldName: 'appendixAddress',
          initialValue: [],
          upload: {
            actionUrl: 'https://dcs-test-api.livanauto.com/api/file/oss/upload',
            fileTypes: ['pdf', 'jpg', 'png', 'rar'],
            limit: 5,
            max: 1024 * 100,
          },
          selfCols: 4
        },
      ];
    },
    // 取表单值通用方法
    findFormItem(fieldName) {
      return this.formList.find(x => x.fieldName === fieldName) || {};
    },
    onRowSelectChange(row) {
      if (!row.length) {
        this.selectRow = null;
      } else {
        this.selectRow = row[0];
      }
    },
    //新增
    addHandle() {
      this.tableParamData.dealDate = moment().format('YYYY-MM-DD HH:mm:ss');
      this.$refs.table.EXECUTE_INSERT(this.tableParamData);
      // 新增后只读新增按钮
      this.addVisable = false;
    },
    // 获取救援单号
    async getOutNoFun() {
      const res = await getOutNo();
      if (res.resultCode === 200) {
        if (res.errMsg) {
          notifyAction(res.errMsg, 'warning');
        } else {
          this.findFormItem('outNo').initialValue = res.data;
        }
      }
    },
    // 初始化
    async initHandle() {
      if (this.type === 'add') {
        // 获取救援单号
        this.getOutNoFun();
        this.tableVisable = false;
      } else if (this.type === 'edit') {
        if(this.formData['outType'] === 55381001){
        this.formList.find(item => item.fieldName === 'crossAmount').hidden = true;
        this.formList.find(item => item.fieldName === 'crossAmount').initialValue = '';
        this.formList.find(item => item.fieldName === 'fuelSubsidy').hidden = false;
        }else if(this.formData['outType'] === 55381002){
        this.formList.find(item => item.fieldName === 'fuelSubsidy').hidden = true;
        this.formList.find(item => item.fieldName === 'fuelSubsidy').initialValue = '';
        this.formList.find(item => item.fieldName === 'crossAmount').hidden = false;
        }
        this.formList.forEach(x => {
          x.initialValue = this.formData[x.fieldName];
        });
        this.formList.find(item => item.fieldName === 'bDate|eDate').initialValue = [this.formData.bDate,this.formData.eDate]
        if (this.formData['fromP']) {
          this.formList.find(item => item.fieldName === 'fromC').itemList = this.createCityList(this.formData.fromP);
        }
        if (this.formData['toP']) {
          this.formList.find(item => item.fieldName === 'toC').itemList = this.createCityList(this.formData.toP);
        }
        if (this.formData['fromC']) {
          this.formList.find(item => item.fieldName === 'fromA').itemList = this.createCityList(this.formData.fromP,this.formData.fromC);
        }
        if (this.formData['toC']) {
          this.formList.find(item => item.fieldName === 'toA').itemList = this.createCityList(this.formData.toP,this.formData.toC);
        }
        this.tableList = this.formData.itemList;
        this.tableVisable = true;
      } else if (this.type === 'detail') {
        this.addVisable = false;
        this.saveVisable = false;
        this.delVisable = false;
        if(this.formData['outType'] === 55381001){
        this.formList.find(item => item.fieldName === 'crossAmount').hidden = true;
        this.formList.find(item => item.fieldName === 'crossAmount').initialValue = '';
        this.formList.find(item => item.fieldName === 'fuelSubsidy').hidden = false;
        }else if(this.formData['outType'] === 55381002){
        this.formList.find(item => item.fieldName === 'fuelSubsidy').hidden = true;
        this.formList.find(item => item.fieldName === 'fuelSubsidy').initialValue = '';
        this.formList.find(item => item.fieldName === 'crossAmount').hidden = false;
        }
        this.formList.forEach(x => {
          x.disabled = true;
          x.initialValue = this.formData[x.fieldName];
        });
        this.formList.find(item => item.fieldName === 'bDate|eDate').initialValue = [this.formData.bDate,this.formData.eDate]
        if (this.formData['fromP']) {
          this.formList.find(item => item.fieldName === 'fromC').itemList = this.createCityList(this.formData.fromP);
        }
        if (this.formData['toP']) {
          this.formList.find(item => item.fieldName === 'toC').itemList = this.createCityList(this.formData.toP);
        }
        if (this.formData['fromC']) {
          this.formList.find(item => item.fieldName === 'fromA').itemList = this.createCityList(this.formData.fromP,this.formData.fromC);
        }
        if (this.formData['toC']) {
          this.formList.find(item => item.fieldName === 'toA').itemList = this.createCityList(this.formData.toP,this.formData.toC);
        }
        this.tableList = this.formData.itemList;
        this.tableVisable = true;
      }
    },
    // 保存
    async saveHandler() {
      let res = null;
      const [err, data] = await this.$refs.formPanel.GET_FORM_DATA();
      if (err) return;
      if (this.type === 'add') {
        res = await saveOut({ ...data, resultItemDTOList: this.tableList });
      }
      if (!isFormEmpty(this.formData) && this.type === 'edit') {
        data.outId = this.formData.outId;
        data.ownerCode = this.formData.ownerCode;
        data.ownerParCode = this.formData.ownerParCode;
        data.appId = this.formData.appId;
        data.createdBy = this.formData.createdBy;
        data.recordVersion = this.formData.recordVersion;
        res = await saveOut({ ...data, resultItemDTOList: this.tableList });
      }
      if (res.resultCode === 200) {
        if (res.errMsg) {
          notifyAction(res.errMsg, 'error');
        } else {
          notifyAction('保存成功！');
          this.closeHandler();
        }
      }
    },
    closeHandler() {
      this.$emit('close', false);
    },
    //vin
    vinOpen() {
      this.vinSelect = true;
    },
    vinClose() {
      this.vinSelect = false;
    },
    async  selectVinSave(obj) {
        if(this.rowDate.vin){
          //如果传进来的vin跟原来的vin不相同就清空table
          if(this.rowDate.vin!== obj[0].VIN){
            let arry = this.$refs.partTakeOntable.$refs.pageTable.list;
            this.$refs.partTakeOntable.$refs.pageTable.EXECUTE_DELETE(arry);
            this.feiyongformList.map(x => {
              if ('partAmount' == x.fieldName) {
                x.initialValue = 0;
                this.partAmountsumz=0;
                this.sumAmount();
              }
            });
          }
        }
        this.rowDate = obj[0];
        this.rowDate.roNo='';
        //页面上是车型名称  下面这两个是给后台传车型代码和车型id  （MODEL对应的是车型id）
        // console.log(obj);
        this.modelCode = obj[0].MODEL_CODE;
        this.modelId = obj[0].MODEL;
        this.powertype = obj[0].POWER_TYPE;
        // let res = await translateByVinAndModelCode({vin:obj[0].VIN,modelCode: obj[0].MODEL_CODE,customerType: obj[0].BUSINESS_KIND});
        this.rowDate.vin= obj[0].VIN;
        let wxLog = await getRoLogList({vin:obj[0].VIN,current:1,limit:100,currentPage:1,pageNum:1,pageSize: 100,size: 100});
        if(wxLog.data.rows.length>=2){
          obj[0].lastDrive = wxLog.data.rows[wxLog.data.rows.length-2].IN_MILEAGE;
        }else{
          obj[0].lastDrive = 0
        }
        this.formList.map(x => {
          if ('vin' == x.fieldName) {
            x.initialValue = obj[0].VIN; //vin
          }
          if ('vhlPlate' == x.fieldName) {
            x.initialValue = obj[0].LICENSE; //车牌号
          }
          if ('vehicleSeries' == x.fieldName) {
            x.initialValue = obj[0].SERIES_NAME; //车系名称
          }
          if ('vehicleType' == x.fieldName) {
            x.initialValue = obj[0].MODEL_NAME; //车型名称
          }
          if ('warrantyStartDate' == x.fieldName) {//保修起始日期
            x.initialValue = obj[0].WRT_END_DATE == null ? null : moment(obj[0].WRT_END_DATE).format('YYYY-MM-DD'); 
          }
          if ('nowMile' == x.fieldName) {
            x.initialValue = obj[0].MILEAGE; //行驶里程
          }
          if ('engineCode' == x.fieldName) {
            x.initialValue = obj[0].ENGINE_NO; //电机号
          }
          if ('ownerName' == x.fieldName) {//车主姓名
            x.initialValue = obj[0].OWNER_NAME;
          }
          if ('ownerTel' == x.fieldName) {//车主手机号
            x.initialValue = obj[0].MOBILE;
          }  
        });
        this.vinSelect = false;
        this.fetchParams = { ...this.fetchParams };

      },
    // 车型
    async getModel(brandsid, seriessid) {
      const res = await getCheModelSelect(brandsid, seriessid);
      this.formList.find(item => item.fieldName === 'model').itemList = res.data.map(x => ({
        value: x.modelId + '',
        text: x.modelName
      }));
    },
    // 清空下拉框表当控件的值和下拉列表
    clearFormItem(item) {
      item.initialValue = undefined;
      item.itemList = [];
    },
    //获取省
    async getProvine() {
      let pl = await this.createRegionList();
      this.formList.find(item => item.fieldName === 'fromP').itemList = pl;
      this.formList.find(item => item.fieldName === 'toP').itemList = pl;
    },
    // 获取市下拉框
    provinceChange(val) {
      this.formList.find((x) => x.fieldName === 'fromC').initialValue = '';
      this.formList.find((x) => x.fieldName === 'fromC').itemList = this.createCityList(val);
    },
    toProvinceChange(val){
      this.formList.find((x) => x.fieldName === 'toC').initialValue = '';
      this.formList.find((x) => x.fieldName === 'toC').itemList = this.createCityList(val);
    },
    // 获取区下拉框
    async cityChange(val) {
      this.formList.find((x) => x.fieldName === 'fromA').initialValue = '';
      this.formList.find((x) => x.fieldName === 'fromA').itemList = this.createCityList(this.formList.find((x) => x.fieldName === 'fromP').initialValue,val);
    },
    async toCityChange(val) {
      this.formList.find((x) => x.fieldName === 'toA').initialValue = '';
      this.formList.find((x) => x.fieldName === 'toA').itemList = this.createCityList(this.formList.find((x) => x.fieldName === 'toP').initialValue,val);
    },
    // //获取省
    // async getProvine() {
    //   const res = await getProvince();
    //   this.formList.find(item => item.fieldName === 'fromP').itemList = res.data.map(x => ({ value: x.regionId + '', text: x.regionName }));
    //   this.formList.find(item => item.fieldName === 'toP').itemList = res.data.map(x => ({ value: x.regionId + '', text: x.regionName }));
    // },
    // // 获取市下拉框
    // async provinceChange(regionId,name) {
    //   if(name === 'fromP'){
    //   this.clearFormItem(this.formList.find(item => item.fieldName === 'fromC'));
    //   if (!regionId) return;
    //     const res = await getCitys(regionId);
    //     this.formList.find(item => item.fieldName === 'fromC').itemList = res.data.map(x => ({ value: x.regionId, text: x.regionName }));
    //   }else{
    //      this.clearFormItem(this.formList.find(item => item.fieldName === 'toC'));
    //   if (!regionId) return;
    //     const res = await getCitys(regionId);
    //     this.formList.find(item => item.fieldName === 'toC').itemList = res.data.map(x => ({ value: x.regionId, text: x.regionName }));
    //   }
    // },
    // // 获取区下拉框
    // async cityChange(regionId,name) {
    //   if(name === 'fromC'){
    //     this.clearFormItem(this.formList.find(item => item.fieldName === 'fromA'));
    //     if (!regionId) return;
    //     const res = await getDistrict(regionId);
    //     this.formList.find(item => item.fieldName === 'fromA').itemList = res.data.map(x => ({ value: x.regionId, text: x.regionName }));
    //   }else{
    //     this.clearFormItem(this.formList.find(item => item.fieldName === 'toA'));
    //     if (!regionId) return;
    //     const res = await getDistrict(regionId);
    //     this.formList.find(item => item.fieldName === 'toA').itemList = res.data.map(x => ({ value: x.regionId, text: x.regionName }));
    //   }
    // },
    //是否拖车下拉框
    async isTrailer(val){
      if(val === 10041002){
        this.formList.find(item => item.fieldName === 'trailerAmount').initialValue = 0;
        this.formList.find(item => item.fieldName === 'trailerAmount').hidden = true;
      }else{
        this.formList.find(item => item.fieldName === 'trailerAmount').hidden = false;
      }
      this.allAmountChange()
    },
    //外出方式下拉框
    async outType(val){
      if(val === 55381001){
        this.formList.find(item => item.fieldName === 'crossAmount').hidden = true;
        this.formList.find(item => item.fieldName === 'crossAmount').initialValue = '';
        this.formList.find(item => item.fieldName === 'fuelSubsidy').hidden = false;
        this.allAmountChange()
      }else if(val === 55381002){
        this.formList.find(item => item.fieldName === 'fuelSubsidy').hidden = true;
        this.formList.find(item => item.fieldName === 'fuelSubsidy').initialValue = '';
        this.formList.find(item => item.fieldName === 'crossAmount').hidden = false;
        this.allAmountChange()
      }else{
        this.formList.find(item => item.fieldName === 'crossAmount').hidden = false;
        this.formList.find(item => item.fieldName === 'fuelSubsidy').hidden = false;
      }
    },
    //上报
    async reported(){
      let res = null;
      const [err, data] = await this.$refs.formPanel.GET_FORM_DATA();
      if (err) return;
      if (!isFormEmpty(this.formData) && this.type === 'edit') {
        data.outId = this.formData['outId']
      }
      res = await reportedOut({ ...data, resultItemDTOList: this.tableList });
      if (res.resultCode === 200) {
        if (res.errMsg) {
          notifyAction(res.errMsg, 'error');
        } else {
          notifyAction('上报成功！');
          this.closeHandler();
        }
      }
    },
    //合计
    allAmountChange(){
      let sum = 0;
      sum += Number(this.formList.find(x => x.fieldName === 'fuelSubsidy').initialValue);
      sum += Number(this.formList.find(x => x.fieldName === 'prSubsidy').initialValue);
      sum += Number(this.formList.find(x => x.fieldName === 'foodSubsidy').initialValue);
      sum += Number(this.formList.find(x => x.fieldName === 'staySubsidy').initialValue);
      sum += Number(this.formList.find(x => x.fieldName === 'crossAmount').initialValue);
      sum += Number(this.formList.find(x => x.fieldName === 'trailerAmount').initialValue);
      sum += Number(this.formList.find(x => x.fieldName === 'otherAmount').initialValue);
      sum += Number(this.formList.find(x => x.fieldName === 'rewardFee').initialValue);
      console.log('sum',Number(this.formList.find(x => x.fieldName === 'fuelSubsidy').initialValue))
      this.formList.find(x => x.fieldName === 'allAmount').initialValue = sum;
    },
    addPartCode() {
      this.partCodeSelect = true
    },
    closePartCode(){
      this.partCodeSelect = false
    },
    partCodeSelectSave(obj){
        this.formList.map(x => {
          if ('partCode' == x.fieldName) {
            x.initialValue = obj[0].partNo; //故障件代码
          }
          if ('partName' == x.fieldName) {
            x.initialValue = obj[0].partName; //故障件名称
          }
        });
        this.partCodeSelect = false;
        this.fetchParams = { ...this.fetchParams };
    }
  }, 
};
</script>
<style lang="less" scoped>
.wrapper {
  height: calc(100vh - 135px);
}
</style>
